﻿using Microsoft.AspNetCore.Mvc;
using SnowTech.SmartTms.App.Interface;
using SnowTech.SmartTms.App;
using SnowTech.SmartTms.App.Line;
using Microsoft.Win32;
using Infrastructure;
using SnowTech.SmartTms.App.Response;
using System;
using SnowTech.SmartTms.App.Line.Response;
using Infrastructure.Extensions;
using SnowTech.SmartTms.App.Request;
using System.Threading.Tasks;
using SnowTech.SmartTms.App.Line.Request;
using System.Collections.Generic;
using SnowTech.SmartTms.Repository.Domain;

namespace SnowTech.SmartTms.Mvc.Controllers
{
    public class LineController : BaseController 
    {
        private readonly LineApp _app;
        private readonly RevelanceManagerApp _revelanceManagerApp;

        public LineController(IAuth authUtil, RevelanceManagerApp revelanceManagerApp,LineApp app) : base(authUtil)
        {
            _revelanceManagerApp = revelanceManagerApp;
            _app = app;
        }


        public IActionResult Index()
        {
            return View();

        }
        public ActionResult Assign()
        {
            return View();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public string Add(LineView obj)
        {
            try
            {
                obj.CreateTime = DateTime.Now;
                obj.UpdateTime = DateTime.Now;
                _app.Add(obj);

            }
            catch (Exception ex)
            {
                Result.Code = 500;
                Result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return JsonHelper.Instance.Serialize(Result);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public string Update(LineView obj)  
        {
            try 
            {
                _app.Update(obj); 

            }
            catch (Exception ex)
            {
                Result.Code = 500;
                Result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return JsonHelper.Instance.Serialize(Result);
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public  string Show(QueryLineListReq request) 
        {
            var objs = _app.Show(request);
            return JsonHelper.Instance.Serialize(objs); 
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public string Delete(string[] ids)
        {
            try
            {
                _app.Delete(ids);
            }
            catch (Exception e)
            {
                Result.Code = 500;
                Result.Message = e.InnerException?.Message ?? e.Message;
            }

            return JsonHelper.Instance.Serialize(Result);
        }
    }
}
